<template>
  <el-container style="height: 100vh; border: 1px solid #eee">
      <el-header style="text-align: right; font-size: 12px">
        <span>{{name}} </span>
        <el-dropdown>
          <i class="el-icon-setting" style="margin-right: 15px"></i>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item><el-button @click="Quit">退出</el-button></el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>

      <el-container>
        <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
          <!-- router属性 为侧边栏开启路由模式 -->
          <el-menu router :default-openeds="[]" :default-active="activePath">
            <el-submenu index="1">
              <template slot="title"><i class="el-icon-s-custom"></i>用户管理</template>
              <el-menu-item-group>
                <el-menu-item @click="saveNavState('/admin')" index="/admin"><i class="el-icon-user-solid"></i>Admin</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
            <el-submenu index="2">
              <template slot="title"><i class="el-icon-menu"></i>菜品管理</template>
              <el-menu-item-group>
                <el-menu-item @click="saveNavState('/cp/addcp')" index="/cp/addcp">添加菜品</el-menu-item>
                <el-menu-item @click="saveNavState('/cp/listcp')" index="/cp/listcp">菜品列表</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
            <el-submenu index="3">
              <template slot="title"><i class="el-icon-tickets"></i>订单管理</template>
              <el-menu-item-group>
                <el-menu-item  @click="saveNavState('/dingdan')" index="/dingdan">订单列表</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
            <el-submenu index="4">
              <template slot="title"><i class="el-icon-edit-outline"></i>公告管理</template>
              <el-menu-item-group>
                <el-menu-item  @click="saveNavState('/gonggaos')" index="/gonggaos">公告列表</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
            <el-submenu index="5">
              <template slot="title"><i class="el-icon-data-line"></i>数据统计</template>
              <el-menu-item-group>
                <el-menu-item  @click="saveNavState('/reports')" index="/reports">数据报表</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>

        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      activePath: '',
      name: ''
    }
  },
  methods: {
    // 退出，清除token值
    Quit () {
      sessionStorage.clear()
      this.$router.push('/login')
    },
    // 保持链接的激活状态
    saveNavState(activePath) {
      sessionStorage.setItem('activePath', activePath)
    }
  },
  created() {
    this.activePath = sessionStorage.getItem('activePath')
    this.name = sessionStorage.getItem('name')
  },
  mounted() {
  }
}
</script>

<style lang="less" scoped>
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    line-height: 60px;
  }

  .el-aside {
    color: #333;
  }

  html,body {
    margin: 0;
    padding: 0;
  }

  .toggle-button{
    background-color:honeydew;
    line-height: 24px;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
</style>
